package vo;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import tool.DateUtils;

@Entity
@NamedQueries({ @NamedQuery(name = "Topic.findAll", query = "select t from Topic t order by updateDttm desc"),
		@NamedQuery(name = "Topic.findByName", query = "select t from Topic t where t.name=?  order by updateDttm desc"),
		@NamedQuery(name = "Topic.findByExpireDttm", query = "select t from Topic t where t.expireDttm=?  order by updateDttm desc"),
		@NamedQuery(name = "Topic.findByNameAndExpireDttm", query = "select t from Topic t where t.name=? and t.expireDttm=?  order by updateDttm desc"),
		@NamedQuery(name = "Topic.findCount", query = "select count(*) from Topic t"), @NamedQuery(name = "Topic.findCountByName", query = "select count(*) from Topic t where name=?"),
		@NamedQuery(name = "Topic.findCountByExpireDttm", query = "select count(*) from Topic t where expireDttm=?"),
		@NamedQuery(name = "Topic.findCountByNameExpireDttm", query = "select count(*) from Topic t where name=? and expireDttm=?")

})
@Table(name = "topic")
public class Topic extends BaseEntity {

	@Column(name = "no")
	String no;
	String name;
	@Column(name = "disabled", nullable = true)
	int disabled;

	String exclude;
	String include;

	String optional;

	@Column(name = "expire_dttm", nullable = true)
	String expireDttm;

	@Column(name = "update_dttm", nullable = true)
	Date updateDttm;

	@Column(name = "warn_limit")
	int warnLimit;

	// 新作的改动
	@Column(name = "isnegative")
	int isNegative;

	@Column(name = "iswarn")
	int isWarn;

	@Column(name = "description")
	String description;


	@OneToMany(fetch = FetchType.LAZY)
	@JoinColumn(name = "topic_id")
	private List<UserTopic> userTopics;

	@Column(name = "keywords")
	String keywords;

	@Column(name = "within_published_time")
	int withinPublishedTime;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getDisabled() {
		return disabled;
	}

	public void setDisabled(int disabled) {
		this.disabled = disabled;
	}

	public String getExclude() {
		return exclude;
	}

	public void setExclude(String exclude) {
		this.exclude = exclude;
	}

	public String getExpireDttm() {
		return expireDttm;
	}

	public String getExpireDttmStr() {
		return expireDttm.substring(0, 10);
	}

	public void setExpireDttm(String expireDttm) {
		this.expireDttm = expireDttm;
	}

	public String getInclude() {
		return include;
	}

	public void setInclude(String include) {
		this.include = include;
	}

	public String getOptional() {
		return optional;
	}

	public void setOptional(String optional) {
		this.optional = optional;
	}

	public int getWarnLimit() {
		return warnLimit;
	}

	public void setWarnLimit(int warnLimit) {
		this.warnLimit = warnLimit;
	}

	public int getIsNegative() {
		return isNegative;
	}

	public void setIsNegative(int isNegative) {
		this.isNegative = isNegative;
	}

	public int getIsWarn() {
		return isWarn;
	}

	public void setIsWarn(int isWarn) {
		this.isWarn = isWarn;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<UserTopic> getUserTopics() {
		return userTopics;
	}

	public void setUserTopics(List<UserTopic> userTopics) {
		this.userTopics = userTopics;
	}

	public Date getUpdateDttm() {
		return updateDttm;
	}

	public String getUpdateDttmStr() {
		return DateUtils.date2DateStr(updateDttm, "-");
	}

	public void setUpdateDttm(Date updateDttm) {
		this.updateDttm = updateDttm;
	}


	public String getNo() {
		return no;
	}

	public void setNo(String no) {
		this.no = no;
	}

	public String getKeywords() {
		return keywords;
	}

	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}

	public int getWithinPublishedTime() {
		return withinPublishedTime;
	}

	public void setWithinPublishedTime(int withinPublishedTime) {
		this.withinPublishedTime = withinPublishedTime;
	}

}
